﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Reflection;
namespace Tal.CaptchaControl
{
    /// <summary>
    /// Summary description for Utils
    /// </summary>
    public class Utils
    {
        public Utils()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        public static string GenerateFromType(string className, TextGenerator.CharacterType characterType)
        {
            Type type = System.Type.GetType(className);
            if (type == null)
            {
                throw new System.Reflection.TargetException("Could not found type \"" + className + "\"");
            }
            ConstructorInfo ci = type.GetConstructor(new Type[] { });
            if (ci == null)
            {
                throw new System.Reflection.TargetException("Could not find default constructor from the type \"" + className + "\"");
            }
            object o = ci.Invoke(null);
            TextGenerator tg = o as TextGenerator;
            if (tg == null)
            {
                throw new System.Reflection.TargetException("Could not create instance of TextGenerator from \"" + className + "\"");
            }
            return tg.Generate(characterType);
        }
    }

    
}